<template>
  <BasicModal
    v-bind="$attrs"
    @register="registerModal"
    :title="getTitle"
    @ok="handleSubmit"
    @cancel="handleClose"
    width="600px"
  >
    <BasicForm @register="registerForm">
      <template #reportTemplateListName="{ model, field }">
        <Transfer
          v-model:target-keys="model[field]"
          :data-source="reportTemplateList"
          :titles="[
            t('routes.project.projectReport.option'),
            t('routes.project.projectReport.outputItem'),
          ]"
          :render="(item) => item.title"
        />
      </template>
    </BasicForm>
  </BasicModal>
</template>

<script setup lang="ts">
  import { ref, computed, unref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { BasicForm, useForm } from '/@/components/Form/index';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { ProjectReportFormSchema } from './tableData';
  import { Transfer } from 'ant-design-vue';

  const { t } = useI18n();
  const { createMessage } = useMessage();

  const emit = defineEmits(['success', 'register']);
  const isUpdate = ref(true);

  const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
    labelWidth: 100,
    schemas: ProjectReportFormSchema,
    showActionButtonGroup: false,
    actionColOptions: {
      span: 23,
    },
  });

  const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
    resetFields();
    setModalProps({ confirmLoading: false });
    isUpdate.value = !!data?.isUpdate;
  });

  const getTitle = computed(() => (!unref(isUpdate) ? t('common.create') : t('common.edit')));
</script>

<style scoped></style>
